package cn.com.pansky.action.homePage;

import java.util.Date;
import java.util.List;

import net.vsame.url2sql.action.BaseAction;
import net.vsame.url2sql.helper.SqlHelper;
import net.vsame.url2sql.sql.Model;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class BannerAction extends BaseAction{
	static BASE64Encoder encoder = new sun.misc.BASE64Encoder(); 
	static BASE64Decoder decoder = new sun.misc.BASE64Decoder(); 
	
	public void  getBanner() {
		String type = getParam("type");
		List<Model> list = SqlHelper.query("sql", type);
		for(int i=0; i<list.size(); i++) {
			Model j = (Model) list.get(i);
			String url = context.getRequest().getRequestURL().toString();
			Date date = new Date();
			Long time = date.getTime();
			j.put("IMAGEURL", url.replace("banner/get.json", "image")+"?id="
			+j.getString("ID")+"&"+time);
		}
		context.put("result", list);
	}
	
	/**
	 * 校验参数
	 * 
	 * @param param
	 * @return
	 */
	protected String getParam(String param) {
			
			if (null == context.getParam(param)) {
				context.putError(-2, " ${" + param + "} must exists");
				return null;
			}
			return context.getParam(param);
	}
}
